package org.hhchat.leetcode.array;

import java.util.Arrays;

public class code88_easy {

    static class Solution {
        public void merge(int[] nums1, int m, int[] nums2, int n) {
            int p=0,q=0;
            int count=0;
            int temp[] = new int[m+n];
            while (p < m || q < n) {
                if(p<m&&q<n){
                    if(nums1[p]>nums2[q]){
                        temp[count++] = nums2[q++];
                    }else{
                        temp[count++] = nums1[p++];
                    }
                }
                else if(p>=m&&q<n){
                    temp[count++] = nums2[q++];
                }
                else if(q>=n&&p<m){
                    temp[count++] = nums1[p++];
                }else{
                    break;
                }
            }
            System.arraycopy(temp, 0, nums1, 0, count);
        }
    }

    public static void main(String[] args){
        Solution solution = new Solution();
        int a[] = {};
        int m=0;
        int b[] = {};
        int n = 0;
        solution.merge(a, m, b, n);
        System.out.println(Arrays.toString(a));
    }
}
